<template>
	<view>
		<u-action-sheet
			:show="options.isShow"
			:actions="options.actions"
			:title="options.title"
			:description="options.description"
			:cancelText="options.cancelText"
			:closeOnClickAction="options.closeOnClickAction"
			:closeOnClickOverlay="options.closeOnClickOverlay"
			:round="options.round"
			@close="_close"
			@select="_select"
		>
		</u-action-sheet>
	</view>
</template>

<script>
	export default {
		name:"c-base-actionSheet",
		data() {
			return {
				options: {},
				defaultOptions: {
					paramName: "",
					isShow: false,
					actions: [],
					title: "请选择",
					description: "",
					cancelText: "",
					closeOnClickAction: true,
					closeOnClickOverlay: true,
					round: 0,
				}
			}
		},
		methods: {
			open(options) {
				this.options = JSON.parse(JSON.stringify(this.defaultOptions))
				if (options) {
					for (let i in this.options) {
						this.options[i] = options[i] || this.options[i]
						if (i == "closeOnClickAction" || i == "closeOnClickOverlay") {
							this.options[i] = options[i] !== false ? true : false
						}
					}
				}
				this.options.isShow = true
				this._hideKeyboard()
			},
			_close() {
				this.options.isShow = false
			},
			_select(item) {
				item.paramName = this.options.paramName
				this.$emit("selected", item)
				this._close()
			},
			_hideKeyboard() {
				uni.hideKeyboard()
			}
		}
	}
</script>

<style scoped lang="scss">

</style>
